<template>
  <div>
    <div v-text="msg"></div>
    <button @click="btn1">发布消息</button>
  </div>
</template>

<script>
import pubsub from 'pubsub-js'
export default {
  name: 'HelloWorld',
  data(){
    return {
      msg:''
    }
  },
  methods:{
    btn1(){
      pubsub.publish('hl','我是HelloWorld组件通过pubsub发布的消息');
    }
  }
  ,mounted() {
    this.$bus.$on('mc',(data)=>{
      this.msg = data
    })
  },
  beforeDestroy() {
    this.$bus.$off('mc')
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
